package com.aimo.base.exceptiondemo.http;

import lombok.Data;

/**
 * @Author: lmy
 * @Date: 2021/2/19 13:53
 * @Description: HTTP结果封装
 */
@Data
public class HttpResult {

	private String code = HttpStatus.SC_OK.getValue();
	private String msg;
	private Object data;
	
	public static HttpResult error() {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR);
	}
	
	public static HttpResult error(String msg) {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR.getValue(), msg);
	}

	public static HttpResult error(HttpStatus httpStatus) {
		return error(httpStatus.getValue(), httpStatus.getName());
	}

	public static HttpResult error(String code, String msg) {
		HttpResult r = new HttpResult();
		r.setCode(code);
		r.setMsg(msg);
		return r;
	}

	public static HttpResult ok(String msg) {
		HttpResult r = new HttpResult();
		r.setMsg(msg);
		return r;
	}
	
	public static HttpResult ok(Object data) {
		HttpResult r = new HttpResult();
		r.setData(data);
		return r;
	}
	
	public static HttpResult ok() {
		return new HttpResult();
	}
}
